<template>
  <ejs-autocomplete :dataSource='userListData'
                    :placeholder="i18nT('custom.clientbot.selectusers')"
                    v-model="selectedUser"
                    @change="onchange"
                    :fields='userFields'></ejs-autocomplete>
</template>

<script>
import i18n from '@/i18n'
export default {
  data () {
    return {
      userFields: {
        value: 'username'
      },

      userListData: [],
      selectedUser: null
    }
  },
  created () {
    this.getUserLists()
  },
  methods: {
    getUserLists () {
      const params = {
        status: 1
      }
      this.$interface.schedule.getUserListApi(params)
        .then(({ data: res }) => {
          if (res.code === 0) {
            this.userListData = res.data.list
          }
        })
    },
    onchange (e) {
      this.$emit('resetSearch', e.value)
    },
    i18nT (key) {
      return i18n.t(key)
    }
  }
}
</script>

<style scoped>

</style>
